package cn.edu.wfit.modules.infomanagement.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.infomanagement.domain.Dorm;
import cn.edu.wfit.modules.infomanagement.service.IDormService;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 宿舍维护Controller
 * 
 * @author 韩强
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/dorm")
public class DormController extends BaseController
{
    @Autowired
    private IDormService dormService;

    /**
     * 查询宿舍维护列表
     */
    @RequiresPermissions("system:dorm:list")
    @GetMapping("/list")
    public TableDataInfo list(Dorm dorm)
    {
        startPage();
        List<Dorm> list = dormService.selectDormList(dorm);
        return getDataTable(list);
    }

    /**
     * 导出宿舍维护列表
     */
    @RequiresPermissions("system:dorm:export")
    @Log(title = "宿舍维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dorm dorm)
    {
        List<Dorm> list = dormService.selectDormList(dorm);
        ExcelUtil<Dorm> util = new ExcelUtil<Dorm>(Dorm.class);
        util.exportExcel(response, list, "宿舍维护数据");
    }

    /**
     * 获取宿舍维护详细信息
     */
    @RequiresPermissions("system:dorm:query")
    @GetMapping(value = "/{dormId}")
    public AjaxResult getInfo(@PathVariable("dormId") Long dormId)
    {
        return success(dormService.selectDormByDormId(dormId));
    }

    /**
     * 新增宿舍维护
     */
    @RequiresPermissions("system:dorm:add")
    @Log(title = "宿舍维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dorm dorm)
    {
        return toAjax(dormService.insertDorm(dorm));
    }

    /**
     * 修改宿舍维护
     */
    @RequiresPermissions("system:dorm:edit")
    @Log(title = "宿舍维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dorm dorm)
    {
        return toAjax(dormService.updateDorm(dorm));
    }

    /**
     * 删除宿舍维护
     */
    @RequiresPermissions("system:dorm:remove")
    @Log(title = "宿舍维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dormIds}")
    public AjaxResult remove(@PathVariable Long[] dormIds)
    {
        return toAjax(dormService.deleteDormByDormIds(dormIds));
    }
}
